<template>
  <div class="common-page f-c">
    <BackPage title="管理人员" />
    <div class="search-params f-r a-c j-b">
      <el-form inline>
        <el-form-item label="用户名称：">
          <el-input clearable v-model="searchParams.realname" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" round @click="onSearch">筛选</el-button>
          <el-button round @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
      <el-form inline>
        <el-form-item>
          <el-button type="primary" @click="onAdd">新增</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="table-box f-g">
      <el-table
        height="100%"
        v-loading="loading"
        stripe
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column type="index" width="80px" label="序号" align="center" />
        <el-table-column prop="realname" label="用户名称" />
        <el-table-column prop="realname" label="头像" width="200px">
          <template slot-scope="scope">
            <el-avatar :size="60" :src="scope.row.headPortrait" />
          </template>
        </el-table-column>
        <el-table-column prop="username" label="登录账号" />
        <el-table-column label="状态">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.status" :active-value="0" :inactive-value="1" @change="(val) => onUpdateStatus(val, scope.row)" />
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="160px">
          <template slot-scope="scope">
            <el-button type="text" @click="onEditPermission(scope.row)">权限配置</el-button>
            <el-button type="text" @click="onEdit(scope.row)">编辑</el-button>
            <el-button type="text" @click="onDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
    <AdminAdd ref="AdminAddRef" />
    <AdminPermission ref="AdminPermissionRef" />
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import AdminAdd from './admin-add'
import AdminPermission from './permission'
import { http_admin_user } from '@/api'

export default {
  name: 'Index',
  components: {
    AdminAdd,
    AdminPermission
  },
  mixins: [crud],
  data() {
    return {
      request: http_admin_user,
      searchParams: {
        realname: ''
      },
      columns: [
        { prop: 'realname', label: '用户名称' },
        { prop: 'avatar', label: '头像' },
        { prop: 'username', label: '登录账号' }
      ],
      tableData: [
      ]
    }
  },
  methods: {
    onEditPermission(item) {
      this.$refs.AdminPermissionRef.open(item)
    },
    onEdit(item) {
      this.$refs.AdminAddRef.open(item)
    },
    onAdd() {
      this.$refs.AdminAddRef.open()
    },
    onUpdateStatus(status, item) {
      http_admin_user.updateStatus({
        id: item.id,
        status
      }).then(res => {
        this.$message.success(res.msg)
      })
    }
  }
}
</script>

<style scoped lang="scss">
</style>
